package com.youku.plugins.videoinfo.view
{
   import flash.display.MovieClip;
   import com.youku.interfaces.IPlayerProxy;
   import flash.utils.Timer;
   import com.youku.events.PlayerControlEvent;
   import flash.events.TimerEvent;
   import flash.events.Event;
   import flash.system.System;
   import com.youku.data.PlayerContext;
   import com.youku.PlayerConfig;
   
   public class VideoInfoPanelMediator extends Object
   {
      
      public function VideoInfoPanelMediator(param1:MovieClip, param2:IPlayerProxy) {
         super();
         this._mainMC = param1;
         this._playerProxy = param2;
         this.init();
      }
      
      private var _mainMC:MovieClip;
      
      private var _playerProxy:IPlayerProxy;
      
      private var _videoInfoPanel:VideoInfoPanel;
      
      protected var _width:Number = 100;
      
      protected var _height:Number = 100;
      
      protected var _full:Boolean = false;
      
      protected var _timer:Timer;
      
      private function init() : void {
         this._videoInfoPanel = new VideoInfoPanel();
         this._playerProxy.addEventListener(PlayerControlEvent.PLAYER_SIZE_CHANGED,this.onPlayerSizeChanged);
         this._playerProxy.addEventListener(PlayerControlEvent.FULLSCREEN_CHANGED,this.onPlayerSizeChanged);
         this._playerProxy.addEventListener(PlayerControlEvent.VIDEO_INFO_SHOW,this.onVideoInfoShow);
         this._videoInfoPanel.addEventListener(VideoInfoPanel.EVENT_VIDEO_PANEL_CLOSE_TEXT,this.onVideoPanelCloseText);
         this._videoInfoPanel.addEventListener(VideoInfoPanel.EVENT_VIDEO_PANEL_CLOSE_BUTTON,this.onVideoPanelCloseButton);
         this._videoInfoPanel.addEventListener(VideoInfoPanel.EVENT_VIDEO_PANEL_COPY,this.onVideoPanelCopy);
         this._timer = new Timer(500);
         this._timer.addEventListener(TimerEvent.TIMER,this.onTimer);
      }
      
      private function onVideoPanelCopy(param1:Event) : void {
         var _loc2_:String = this._videoInfoPanel.infoString;
         System.setClipboard(_loc2_);
      }
      
      private function onVideoPanelCloseButton(param1:Event) : void {
         this.close();
      }
      
      private function onVideoPanelCloseText(param1:Event) : void {
         this.close();
      }
      
      private function close() : void {
         if(this._mainMC.contains(this._videoInfoPanel))
         {
            this._mainMC.removeChild(this._videoInfoPanel);
         }
         this._timer.stop();
      }
      
      private function onVideoInfoShow(param1:PlayerControlEvent) : void {
         if(this._mainMC.contains(this._videoInfoPanel))
         {
            this._mainMC.removeChild(this._videoInfoPanel);
         }
         this._mainMC.addChild(this._videoInfoPanel);
         this.updateLayout();
         this._videoInfoPanel.show();
         this._timer.reset();
         this._timer.start();
         this.updateVideoInfo();
      }
      
      private function onTimer(param1:TimerEvent) : void {
         this.updateVideoInfo();
      }
      
      private function updateVideoInfo() : void {
         var _loc1_:Object = {};
         _loc1_.width = this._width;
         _loc1_.height = this._height;
         _loc1_.videowidth = this._playerProxy.playerData.videoCurrentRealWidth;
         _loc1_.videoheight = this._playerProxy.playerData.videoCurrentRealHeight;
         _loc1_.volume = int(PlayerContext.volume * 100);
         _loc1_.fps = this._playerProxy.playerData.getSegmentStatusByNumber(this._playerProxy.playerData.currentVideoNum).fps;
         _loc1_.dfps = this._playerProxy.playerData.droppedFrames;
         _loc1_.num = this._playerProxy.playerData.currentLoadingNum;
         _loc1_.speed = this._playerProxy.playerData.getSegmentStatusByNumber(this._playerProxy.playerData.currentLoadingNum).currSpeed;
         _loc1_.svavaible = PlayerConfig.isStageVideoAvailable;
         _loc1_.svinuse = PlayerConfig.isStageVideoInUse;
         _loc1_.decode = PlayerConfig.videoDecodeStatus;
         this._videoInfoPanel.updateInfo(_loc1_);
      }
      
      private function onPlayerSizeChanged(param1:PlayerControlEvent) : void {
         var _loc2_:Number = param1.data.width;
         var _loc3_:Number = param1.data.height;
         var _loc4_:Number = param1.data.cheight;
         var _loc5_:Boolean = param1.data.fullscreen;
         this._width = _loc2_;
         this._height = _loc3_ - (_loc5_?0:_loc4_);
         this._full = _loc5_;
         if(this._videoInfoPanel != null)
         {
            this._videoInfoPanel.setSize(this._width,this._height);
         }
         this.updateLayout();
      }
      
      private function updateLayout() : void {
         this._videoInfoPanel.x = 10;
         this._videoInfoPanel.y = this._full?40:10;
      }
   }
}
